{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question-answering skill"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>question</th>\n",
       "      <th>expected_answer</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>In quantum mechanics, what principle asserts t...</td>\n",
       "      <td>Heisenberg Uncertainty Principle</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Which famous poet wrote 'The Love Song of J. A...</td>\n",
       "      <td>T.S. Eliot</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>What mathematical theorem states that in any r...</td>\n",
       "      <td>Pythagorean Theorem</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Which philosophical paradox involves a ship wh...</td>\n",
       "      <td>Ship of Theseus</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>In the world of programming, what is the desig...</td>\n",
       "      <td>Open/Closed Principle</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            question  \\\n",
       "0  In quantum mechanics, what principle asserts t...   \n",
       "1  Which famous poet wrote 'The Love Song of J. A...   \n",
       "2  What mathematical theorem states that in any r...   \n",
       "3  Which philosophical paradox involves a ship wh...   \n",
       "4  In the world of programming, what is the desig...   \n",
       "\n",
       "                    expected_answer  \n",
       "0  Heisenberg Uncertainty Principle  \n",
       "1                        T.S. Eliot  \n",
       "2               Pythagorean Theorem  \n",
       "3                   Ship of Theseus  \n",
       "4             Open/Closed Principle  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.DataFrame([\n",
    "    {\"question\": \"In quantum mechanics, what principle asserts that it's impossible to simultaneously know the exact position and momentum of a particle?\", \"expected_answer\": \"Heisenberg Uncertainty Principle\"},\n",
    "    {\"question\": \"Which famous poet wrote 'The Love Song of J. Alfred Prufrock'?\", \"expected_answer\": \"T.S. Eliot\"},\n",
    "    {\"question\": \"What mathematical theorem states that in any right-angled triangle, the area of the square whose side is the hypotenuse is equal to the sum of the areas of the squares whose sides are the two legs?\", \"expected_answer\": \"Pythagorean Theorem\"},\n",
    "    {\"question\": \"Which philosophical paradox involves a ship where all of its wooden parts are replaced with metal parts?\", \"expected_answer\": \"Ship of Theseus\"},\n",
    "    {\"question\": \"In the world of programming, what is the design principle that suggests a system should be open for extension but closed for modification?\", \"expected_answer\": \"Open/Closed Principle\"}\n",
    "])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Applying skill: question_answering\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Applying skill: question_answering\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█| 5/5 [00:01<00:00, \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>question</th>\n",
       "      <th>expected_answer</th>\n",
       "      <th>answer</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>In quantum mechanics, what principle asserts t...</td>\n",
       "      <td>Heisenberg Uncertainty Principle</td>\n",
       "      <td>The Heisenberg uncertainty principle.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Which famous poet wrote 'The Love Song of J. A...</td>\n",
       "      <td>T.S. Eliot</td>\n",
       "      <td>T.S. Eliot</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>What mathematical theorem states that in any r...</td>\n",
       "      <td>Pythagorean Theorem</td>\n",
       "      <td>The Pythagorean theorem.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Which philosophical paradox involves a ship wh...</td>\n",
       "      <td>Ship of Theseus</td>\n",
       "      <td>The Ship of Theseus paradox.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>In the world of programming, what is the desig...</td>\n",
       "      <td>Open/Closed Principle</td>\n",
       "      <td>The design principle is called the Open-Closed...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            question  \\\n",
       "0  In quantum mechanics, what principle asserts t...   \n",
       "1  Which famous poet wrote 'The Love Song of J. A...   \n",
       "2  What mathematical theorem states that in any r...   \n",
       "3  Which philosophical paradox involves a ship wh...   \n",
       "4  In the world of programming, what is the desig...   \n",
       "\n",
       "                    expected_answer  \\\n",
       "0  Heisenberg Uncertainty Principle   \n",
       "1                        T.S. Eliot   \n",
       "2               Pythagorean Theorem   \n",
       "3                   Ship of Theseus   \n",
       "4             Open/Closed Principle   \n",
       "\n",
       "                                              answer  \n",
       "0              The Heisenberg uncertainty principle.  \n",
       "1                                         T.S. Eliot  \n",
       "2                           The Pythagorean theorem.  \n",
       "3                       The Ship of Theseus paradox.  \n",
       "4  The design principle is called the Open-Closed...  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from adala.agents import Agent\n",
    "from adala.skills.collection.qa import QuestionAnsweringSkill\n",
    "\n",
    "agent = Agent(skills=QuestionAnsweringSkill())\n",
    "\n",
    "agent.run(df)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "adala",
   "language": "python",
   "name": "adala"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
